﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using ExtBusiness;
using System.Configuration;
using WebControls;
using Common;
using ExtBusiness.Interface;

public partial class office_GetApplicationInfo : System.Web.UI.Page
{
    private string strFlowid = string.Empty;
    private string strFlowName = string.Empty;//
    private string strappid = string.Empty;//申请单号
    private string strappOrgName = string.Empty;//申请单位
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["flowname"] != null)
        {
            strFlowName = Request["flowname"].ToString();
        }
        //获取 单位名称, appid(申请单号)addby zhongjian 20090909
        gridviewCar.DataKeyNames = new string[] {"单位名称","appid" };
        if (!IsPostBack)
        {
            BindUtInfo();
        }
    }

    #region 数据绑定
    /// <summary>
    /// 获取并添加待处理业务接口信息
    /// </summary>
    /// <!--获取并添加待处理业务接口信息 edit by zhongjian 20090908-->
    private void GridBindding()
    {
        DxInterface.IdsService idsTemp = new DxInterface.IdsService();
        InterfaceOperation infaceOperation = new InterfaceOperation();

        string strCheckCode = Encode.Md5(DateTime.Now.ToShortDateString());
        //status:   0:新提交的申请；-1:已获取过的申请信息；1:已经审批结束
        //appDateStart: 字符型，格式限定为YYYY-MM-DD
        string strTemp = idsTemp.GetApplication("", "", "", strCheckCode);
        DataSet dsTemp = infaceOperation.GetDatasetFromXml(strTemp);

        if (dsTemp.Tables.Count > 0)
        {
            infaceOperation.InsertInfaceData(dsTemp, Session["UserName"].ToString());
        }        
    }
    /// <summary>
    /// 绑定待处理业务数据
    /// </summary>
    private void BindUtInfo()
    {
        InterfaceOperation infaceOperation = new InterfaceOperation();
        DataTable dt = new DataTable();
        string SerialFlowType = SystemConfig.InterfaceSerialName;//国家涉密基础测绘成果使用申报
        if (SerialFlowType.Contains(strFlowName))
        {
            GridBindding();
            dt = infaceOperation.GetUtInfo(txtappOrgName.Value, "", "", txtaecOrgName.Value, "", "", "", "", "");            
        }
        else
        {
            dt = infaceOperation.GetUtInfoOld(strFlowName, txtappOrgName.Value, txtaecOrgName.Value);
        }
        gridviewCar.DataSource = dt;
        gridviewCar.RecordCount = dt.Rows.Count;
        gridviewCar.DataBind();
    }
    private void ClearText()
    {
        txtappOrgName.Value = "";
        txtaecOrgName.Value = "";
    }
    #endregion

    /// <summary>
    /// datagrid数据加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void recvgrid_OnLoadData(object sender, EventArgs e)
    {
        this.BindUtInfo();
    }

    /// <summary>
    /// 完成事件
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="Antu.WebControls.CustomGridViewEventArgs"/> instance containing the event data.</param>
    protected void gridviewCar_OnComplelteClick(object sender, CustomGridViewEventArgs e)
    {
        if (e == null)
        {
            return;
        }
        else if (e.SingleOrMultiSelectKey.Value.ToString() == "")
        {
            return;
        }
        strappOrgName = e.SingleOrMultiSelectKey.Values["单位名称"].ToString();
        strappid = e.SingleOrMultiSelectKey.Values["appid"].ToString();
        if (string.IsNullOrEmpty(strappid))
        {
            //当受理涉密原数据时,没有地信中心关联值:appid,因此不传此值 edit by zhongjian 20091019
            ClientScript.RegisterStartupScript(this.GetType(), "scr", string.Format(@"<script>window.opener.document.getElementById(""txtUserName"").value='{0}';window.close();</script>", strappOrgName));
        }
        else
        {
            //将申请单位直接写入父页面申请单位文本框中 addby zhongjian 20090908
            ClientScript.RegisterStartupScript(this.GetType(), "scr", string.Format(@"<script>window.opener.document.getElementById(""txtUserName"").value='{0}';window.opener.document.getElementById(""hidappid"").value={1};window.close();</script>", strappOrgName, strappid));
        }
    }

    protected void gridviewCar_OnCancelClick(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "scr", string.Format(@"<script>window.close();</script>"));
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        BindUtInfo();
    }
    protected void gridviewCar_PageIndexChanged(object sender, EventArgs e)
    {
        BindUtInfo();
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        ClearText();
    }

}
